<template>
	<view>
		<u-modal title='温馨提示' v-model="show" :show-confirm-button='false' :mask-close-able='false'>
			<view class="auth-box">
				<view class="auth-title">
					您还未登录，请点击下方授权按钮，以便给您提供更多服务。
				</view>
				<u-button @click="handLogin" type='jz' :ripple="true">登录</u-button>
				<view class="look-title" @click="handNavLook">
					再看看
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: true,
				userCode: ''
			};
		},
		methods: {
			handLogin() {
				let _this = this
				uni.login({
					success: function(res) {
						_this.$u.api.login({
							code: res.code
						}).then(resInfo => {
							//userCode就是token
							_this.userCode = resInfo.userCode
							if (resInfo && resInfo.phone) {
								_this.cache.setCache('phone', resInfo.phone)
								_this.cache.setCache('userCode', resInfo.userCode)
								_this.cache.setCache('userMsg', resInfo)
								uni.navigateBack({
									delta: 2
								})
							} else {
								uni.showToast({
									title: '请授权手机号以获得完整服务',
									icon: 'none'
								})
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/authPages/authPhone?userCode=' + _this.userCode
									})
								}, 1000)
							}
							console.log(resInfo, '用户信息', res)
						})
					}
				})
			},
			handNavLook() {
				uni.navigateBack({
					delta: 2
				})
			}
		}
	}
</script>

<style lang="scss">
	.auth-box {
		padding: 60upx;

		.auth-title {
			margin-bottom: 60upx;
		}

		.look-title {
			font-size: $bs-font-size-24;
			color: $bs-text-color-999;
			text-align: center;
			width: 100%;
			margin-top: 20rpx;
			// color: $bs;
		}
	}
</style>
